<template>
  <li :class="{line:item.checked}">
    <label>
      <!--v-model脏数据  直接修改了app组件内的数据 不可取-->
      <!--<input type="checkbox" v-model="item.checked" />-->

      <!--<input type="checkbox" v-model="checked" />-->
      <input type="checkbox"
             :checked="item.checked" @change="updateChecked" />
      <span>{{item.content}}</span>
    </label>
    <button class="btn btn-danger" @click="detTask">删除</button>
  </li>
</template>

<script>
    export default {
        name: "todo-item",
        props:["item"],
        /*computed:{
          checked:{
            get(){return this.item.checked},
            set(newVal){
              //newVal : 点击后 复选框最新的状态
              // console.log(newVal,this.item.id);
              this.$bus.$emit("updateChecked",this.item.id,newVal)
            }
          }
        },*/
        methods:{
          //删除指定待办任务的
          detTask(){this.$bus.$emit("detTask",this.item.id)},
          //修改指定任务的选中状态
          updateChecked(ev){
            this.$bus.$emit("updateChecked",this.item.id,ev.target.checked)
          }
        }
    }
</script>

<style scoped>
  /*damu add start*/
  li button{display: none}
  li:hover{background: pink}
  li:hover button{display: block}

  li{position: relative}
  li.line:after{
    display: block;
    content: "";
    width: 60%;
    height: 2px;
    background: red;

    position: absolute;
    left: 30px;
    top: 0;
    bottom: 0;
    margin: auto;
  }
  /*damu add end*/


  li {
    list-style: none;
    height: 36px;
    line-height: 36px;
    padding: 0 5px;
    border-bottom: 1px solid #ddd;
  }

  li label {
    float: left;
    cursor: pointer;
  }

  li label li input {
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    top: -1px;
  }

  li button {
    float: right;
    margin-top: 3px;
  }

  li:before {
    content: initial;
  }

  li:last-child {
    border-bottom: none;
  }

</style>
